'***************************************************************************\
' Module Name: SetMediaForHomeTheater.vbs
' Project: SetDefaultAudioEndpoint http://sdae.codeplex.com/
' Copyright 2011 by jeff
' 
' This source is subject to the GNU General Public License version 2 (GPLv2).
' See http://www.gnu.org/licenses/gpl-2.0.html.
' All other rights reserved.
' 
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'***************************************************************************/

option explicit

'
'SetDefaultAudioEndpoint execution script
'
'This VBScript script can be used to set up your computer for home theater use. The script (or a shortcut to it) was intended
' to be placed in your Windows 7 "Startup" folder so it will execute when you log on to a user account
' dedicated to home theater use. Script overview:
'
' 1. Ask if you would like to set up your computer for home theater use.
' 2. Change your Windows 7 system audio playback device.
' 3. Change your video setup.
'
'The following examples assume that you have unpacked the SetDefaultAudioEndpoint into a folder named
' "SetDefaultAudioEndpoint" in your "Documents" folder.
'
'You can create a shortcut to execute this script. This is the shortcut's "Target":
'
'C:\Windows\System32\wscript.exe "C:\Users\HomeTheaterUser\Documents\SetDefaultAudioEndpoint\SetMediaForHomeTheater.vbs"
'
'
'IMPORTANT: You must change the following items!
'
'IMPORTANT: Do not put spaces between command line parameters and arguments!
'
'Note the double quotes around the parameters. This is because the parameter names contain spaces,
' and so would require quotes if the applications were executed from the command line. In this script,
' the quotes must be "escaped" with double quotes. For example, to call the audio application from the command line:
'
' > SetDefaultAudioEndpoint.exe -p"ATI  DP  Output"
'
'
'!!!BEGIN REQUIRED CHANGES!!!
'

const AUDIO_APPLICATION_PATH_AND_ENDPOINT = "C:\Users\HomeTheaterUser\Documents\SetDefaultAudioEndpoint\SetDefaultAudioEndpoint.exe -p""ATI  DP  Output"" "

const VIDEO_APPLICATION_PATH_AND_PROFILE = "C:\Program Files\ATI Technologies\ATI.ACE\Core-Static\CLI.exe Start Load profilename=""HomeTheaterProfile"" "

'
'!!!END REQUIRED CHANGES!!!
'


dim objShell, objWshScriptExec, objStdErr, strOutput
dim messageboxResult

messageboxResult = MsgBox("Do you want to set up this computer for Home Theater use?", vbYesNo, "Set up for Home Theater?")

if (messageboxResult = vbNo) then
	WScript.Quit(0)
end if

'Get the Windows Script Host command shell
set objShell = CreateObject("WScript.Shell")

'Execute SetDefaultAudioEntpoint.exe with the given audio playback device
set objWshScriptExec = objShell.Exec(AUDIO_APPLICATION_PATH_AND_ENDPOINT)

'Get error output from our executing application
set objStdErr = objWshScriptExec.StdErr

'Read error output buffer
strOutput = objStdErr.ReadAll

'If we got any output, display it for user
if (len(strOutput) >= 1) then
  WScript.Echo AUDIO_APPLICATION_PATH_AND_ENDPOINT & " returned this error message:" & vbCrLf & vbCrLf & strOutput
end if

'Execute our graphic card's profile selection application
set objWshScriptExec = objShell.Exec(VIDEO_APPLICATION_PATH_AND_PROFILE)

'Not sure if graphic card application has error output, but we will try
set objStdErr = objWshScriptExec.StdErr
strOutput = objStdErr.ReadAll

if (len(strOutput) >= 1) then
	WScript.Echo VIDEO_APPLICATION_PATH_AND_PROFILE & " returned this error message:" & vbCrLf & vbCrLf & strOutput
end if

